package mytest;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/8/25 16:26
 * 内存可见性
 */
public class TestVolatile {
    public static void main(String[] args) throws InterruptedException {
        A a = new A();
        a.start();
        Thread.sleep(1000);
        a.flag = false;
    }
}

class A extends Thread {

    volatile boolean flag = true;

    @Override
    public void run() {
        System.out.println("start");
        while (flag) {
//            System.out.println();
        }
        System.out.println("end");
    }
}